// pages/find/classmate/classmate.js
const app = getApp()
var base_url = app.globalData.url
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mengban:'none'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({

      success: function (res) {
        let clientHeight = res.windowHeight;
        let clientWidth = res.windowWidth;
        let ratio = 750 / clientWidth;
        let height = clientHeight * ratio;
        that.setData({
          height: clientHeight
        });
      }
    });
    wx.getStorage({
      key: 'classmates_lst',
      success: function (res) {
        that.setData({
          classmates_lst:res.data
        })
      },
    })
    wx.getStorage({
      key: 'getClassId',
      success: function (res) {
        that.setData({
          getClassId: res.data
        })
        console.log("213123333333333333333")
        console.log(that.data.getClassId)
      },
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  deleteClass:function(){
    var that = this
    // that.setData({
    //   mengban: "block"
    // })
    wx.showModal({
      title: "提示",
      content: "您确认解散班级吗？ 注：解散班级后，班级所有学生将自动退出班级，解散前要提前对班级家长做好说明。",
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: base_url + '/removeClass/',
            method: 'POST',
            data: {
              getClassId: that.data.getClassId
            },
            header: {
              "Content-Type": "application/x-www-form-urlencoded"
            },
            success: function (res) {
              if (res.data['flag'] == true) {
                wx.showModal({
                  title: "提示",
                  content: "解散成功",
                  success: function (res) {
                    if (res.confirm) {
                      wx.redirectTo({
                        url: '../find',
                      })
                    } else {
                      wx.redirectTo({
                        url: '../find',
                      })
                    }
                  }
                })
                
              }
            }
          })
        } else {

        }
      }
    })
  },
  back: function () {
    this.setData({
      mengban: "none"
    })
  },
  sure: function () {
    this.setData({
      mengban: "none"
    })
  },
  removeMember:function(e){
    var that = this
    var student_id = e.currentTarget.dataset.name
    wx.request({
      url: base_url + '/removeMember/',
      method: 'POST',
      data: {
        student_id: student_id
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        if (res.data['flag'] == true) {
          wx.showModal({
            title: "提示",
            content: "移除成功",
            success: function (res) {
              if (res.confirm) {
                wx.request({
                  url: base_url + '/getAllclassmates/',
                  method: 'POST',
                  data: {
                    getClassId: that.data.getClassId
                  },
                  header: {
                    "Content-Type": "application/x-www-form-urlencoded"
                  },
                  success: function (res) {
                    if (res.data['flag'] == true) {


                      
                      wx.setStorage({
                        key: 'classmates_lst',
                        data: res.data['classmates_lst'],
                        success: function (res) {
                          that.onLoad()
                          
                          // wx.navigateTo({
                          //   url: 'classmate/classmate'
                          // })
                        }
                      })
                      

                    }
                  }
                })
                
              } else {

              }
            }
          })

        }
      }
    })
  }
})